<template>
  <div>
    <div class="PageTools-container">
      <div class="app-container">
        <PageTools>
          <template #left>
            <span>共有数据{{ total }}条</span>
          </template>
          <template #right>
            <el-button type="primary" size="small">历史归档</el-button>
            <el-button type="primary" size="small">导出</el-button>
          </template>
        </PageTools>
        <el-card style="margin-top: 10px">
          <el-table border :data="list">
            <el-table-column label="序号" type="index" sortable="" />
            <el-table-column label="姓名" prop="username" sortable="" />
            <el-table-column label="手机号" prop="mobile" sortable="" />
            <el-table-column label="工号" prop="workNumber" sortable="" />
            <el-table-column
              label="聘用形式"
              prop="formOfEmployment"
              :formatter="formatterFn"
              sortable=""
            />
            <el-table-column label="部门" prop="departmentName" sortable="" />
            <el-table-column label="入职时间" prop="timeOfEntry" sortable="">
              <template #default="{ row }">
                {{ row.timeOfEntry | formaterTime('YYYY年MM月DD日') }}</template
              >
            </el-table-column>
            <el-table-column label="操作" sortable="" fixed="right" width="280">
              <template>
                <el-button type="text" size="small">查看</el-button>
                <el-button type="text" size="small">转正</el-button>
                <el-button type="text" size="small">调岗</el-button>
                <el-button type="text" size="small">离职</el-button>
                <el-button type="text" size="small">角色</el-button>
                <el-button type="text" size="small">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页组件 -->
          <el-pagination
            :current-page="page"
            :page-sizes="[1, 2, 3, 4, 5]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            v-loading="loading"
          />
        </el-card>
      </div>
    </div>
  </div>
</template>
<script>
//请求员工列表
import { reqGetEmployeeList } from '@/api/emplysess'
import obj from '@/api/constant/employees'
export default {
  data() {
    return {
      list: [],
      total: 0,
      page: 1, //当前页码
      pagesize: 5, //每页数据条数
      loading: false
    }
  },
  created() {
    this.getUserList()
  },
  methods: {
    async getUserList() {
      this.loading = true
      const { data } = await reqGetEmployeeList(this.page, this.pagesize)
      this.list = data.rows
      this.total = data.total
      this.loading = false
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`)
      // 更新当前页
      this.page = val
      // 调用方法, 重新请求渲染
      this.getRoleList()
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`)
      // 更新每页条数
      this.pagesize = val
      // 重置当前页
      this.page = 1
      // 调用方法, 重新请求
      this.getRoleList()
    },
    formatterFn(row, column, cellValue, index) {
      //row 一行的数据
      //column 列的各种信息 几乎用不到
      //cellValue 当前列的值
      //index 索引
      console.log(row, column, cellValue, index)
      const { hireType } = obj
      const result = hireType.find((item) => item.id === cellValue)
      return result ? result.value : '未知'
    }
  }
}
</script>
<style scoped></style>
